package com.gf.service.impl;

import com.gf.bean.BackInfo;
import com.gf.bean.GetorderInfo;
import com.gf.bean.Orderr;
import com.gf.bean.OrderrInfo;
import com.gf.dao.OrderrMapper;
import com.gf.dao.ShopMapper;
import com.gf.dao.UserMapper;
import com.gf.service.OrderrService;
import com.gf.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class OrderrServiceImpl implements OrderrService {


    @Override
    public int insert(Orderr record) {

        SqlSession sqlSession = MybatisUtils.getsqlSession();
          sqlSession.getMapper(OrderrMapper.class).insert(record);
        MybatisUtils.closesqlSession(sqlSession);
        return 0;
    }

    @Override
    public int updateorderbysendid(Orderr order) {SqlSession sqlSession = MybatisUtils.getsqlSession();
        int updateorderbysendid = sqlSession.getMapper(OrderrMapper.class).updateorderbysendid(order);

        MybatisUtils.closesqlSession(sqlSession);

        return updateorderbysendid;
    }


    @Override
    public List<Orderr> selectAll() {
        return null;
    }

    @Override
    public int selectorderbuyid(String order_id) {
        SqlSession sqlSession = MybatisUtils.getsqlSession();
        int selectorderbuyid = sqlSession.getMapper(OrderrMapper.class).selectorderbuyid(order_id);
        MybatisUtils.closesqlSession(sqlSession);
        return selectorderbuyid;
    }


    @Override
    public List<OrderrInfo> selectnosendidorder() {
        SqlSession sqlSession = MybatisUtils.getsqlSession();
        List<OrderrInfo> selectnosendidorder = sqlSession.getMapper(OrderrMapper.class).selectnosendidorder();
        MybatisUtils.closesqlSession(sqlSession);
        return selectnosendidorder;
    }

    @Override
    public List<Orderr> selectmyAllorders(int user_id) {
        SqlSession sqlSession = MybatisUtils.getsqlSession();
        List<Orderr> myorders = sqlSession.getMapper(OrderrMapper.class).selectmyAllorders(user_id);
        MybatisUtils.closesqlSession(sqlSession);
        return myorders;
    }

    @Override
    public List<GetorderInfo> selectmysendorders(int user_id) {
        SqlSession sqlSession = MybatisUtils.getsqlSession();
        List<GetorderInfo> myorders = sqlSession.getMapper(OrderrMapper.class).selectmysendorders(user_id);
        MybatisUtils.closesqlSession(sqlSession);
        return myorders;
    }

    @Override
    public int setorderendtime(Orderr order) {
        SqlSession sqlSession = MybatisUtils.getsqlSession();
        int flag = sqlSession.getMapper(OrderrMapper.class).setorderendtime(order);
        MybatisUtils.closesqlSession(sqlSession);
        return flag;
    }

    @Override
    public List<GetorderInfo> selectmybuyorders(int user_id) {
        SqlSession sqlSession = MybatisUtils.getsqlSession();
        List<GetorderInfo> myorders = sqlSession.getMapper(OrderrMapper.class).selectmybuyorders(user_id);
        MybatisUtils.closesqlSession(sqlSession);
        return myorders;
    }

    @Override
    public int deleteorderbyorderid(Orderr order) {
        SqlSession sqlSession = MybatisUtils.getsqlSession();
        int flag = sqlSession.getMapper(OrderrMapper.class).deleteorderbyorderid(order);
        MybatisUtils.closesqlSession(sqlSession);
        return flag;
    }
    public BackInfo selectbackinfo(){
        SqlSession sqlSession = MybatisUtils.getsqlSession();
        int ordercount = sqlSession.getMapper(OrderrMapper.class).selectallordercount();
        int shopcount = sqlSession.getMapper(ShopMapper.class).selectallshopcount();
        int usercount = sqlSession.getMapper(UserMapper.class).selectallusercount();
        BackInfo backInfo = new BackInfo();
        backInfo.setOrdercount(ordercount);
        backInfo.setShopcount(shopcount);
        backInfo.setUsercount(usercount);
        MybatisUtils.closesqlSession(sqlSession);
        return backInfo;
    }

}
